import http from '@/utils/service';

const API = {
  getCoupon: '/coupon/getCoupon',
  getUserNoCoupon: '/coupon/getUserNoCoupon',
  createCoupon: '/coupon/createCoupon',
  getUser: '/coupon/getUser?id=',
  receiveCoupon: '/coupon/receiveCoupon',
  getMyCoupon: '/coupon/getMyCoupon?userId=',
};

export interface DataType {
  id: number;
  title: string;
  description: string;
  discount: number;
  minimumAmount: number;
  startTime: string;
  endTime: number;
  state: number;
}

export interface GetCoupon {
  restaurantId: number;
  current: number;
  size: number;
  sortField: string;
  sortOrder: string;
  userId: number;
}

export interface CreateCoupon {
  rId: number;
  title: string;
  description: string;
  discount: number;
  startTime: string;
  endTime: string;
}
export interface getUser {
  id: number;
  userName: string;
  status: number;
}
export interface receiveCoupon {
  couponId: number;
  userId: number;
}

export const getCouponAPI = (data: GetCoupon) =>
  http.post(API.getCoupon, { data });
export const getUserNoCouponAPI = (data: GetCoupon) =>
  http.post(API.getUserNoCoupon, { data });

export const createCouponAPI = (data: CreateCoupon) =>
  http.post(API.createCoupon, { data });

export const getUserAPI = (id: number) => http.get(API.getUser + id);
export const receiveCouponAPI = (data: receiveCoupon) =>
  http.post(API.receiveCoupon, { data });

export const getMyCouponAPI = (id: number) => http.get(API.getMyCoupon + id);
